﻿var oPopup = null;
var FileUploadPath = "";
//事件邦定
$(document).ready(function () {
    oPopup = $("#oPopup");
    if (oPopup.length == 0) {
        $('body').append("<div id=\"oPopup\"></div>");
    }
    oPopup = $("#oPopup");
});

function ShowDialgForUpload(_element) {
    show_dialog("../File_upload.aspx?control=" + _element + "&path=" + FileUploadPath, 400, 100, "文件上传");
}

function ShowDialgForFile(_action, _srcValue) {
    window.open(_srcValue, '', 'width=300,height=170,resizable=1,scrollbars=yes');
}

function commonInputPicker(_action, _element) {

    var _oPopBody = oPopup;

    var _ElementControl = $('#' + _element);

    var _srcValue = _ElementControl.val();

    var IMG_HTMLContent =
                    '<table class="table_form"> ' +
					'  <tr class="tr_item pointer" onClick="ShowDialgForUpload(\'' + _element + '\');return false;" title="上传图片" >  ' +
					'    <th height="20" onmouseover="this.className=\'menu_mouseover\'" class="menu_mouseout"  onmouseout="this.className=\'menu_mouseout\'"> 上传图片  </th> ' +
                    '  </tr> ' +
					'  <tr class="tr_item pointer" onClick="ShowDialgForFile(\'img_preview\', \'' + _srcValue + '\');return false;" title="图片预览" >  ' +
					'    <th height="20" onmouseover="this.className=\'menu_mouseover\'" class="menu_mouseout"  onmouseout="this.className=\'menu_mouseout\'"> 图片预览  </th> ' +
					'  </tr> ' +
					'</table> ';

    var ATTACH_HTMLContent =
                    '<table class="table_form"> ' +
					'  <tr class="tr_item pointer" onClick="ShowDialgForUpload(\'' + _element + '\');return false;" title="上传附件" >  ' +
					'    <th height="20" onmouseover="this.className=\'menu_mouseover\'" class="menu_mouseout"  onmouseout="this.className=\'menu_mouseout\'"> 上传附件  </th> ' +
                    '  </tr> ' +
					'  <tr class="tr_item pointer" onClick="ShowDialgForFile(\'img_preview\', \'' + _srcValue + '\');return false;" title="附件下载" >  ' +
					'    <th height="20" onmouseover="this.className=\'menu_mouseover\'" class="menu_mouseout"  onmouseout="this.className=\'menu_mouseout\'"> 附件下载  </th> ' +
					'  </tr> ' +
					'</table> ';


    switch (_action) {
        case 'img':
            _oPopBody.html(IMG_HTMLContent);
            break;
        case 'attach':
            _oPopBody.html(ATTACH_HTMLContent);
            break;
    }

    var offset = _ElementControl.offset();
    _oPopBody.css({ position: "absolute", zIndex: 1000 })
    _oPopBody.css({ top: offset.top - 5, left: event.clientX - 10 });
    _oPopBody.css({ width: "100px", height: "90px" });
    _oPopBody.show();
    _oPopBody.mouseout(function () { _oPopBody.hide(); });
    _oPopBody.mouseover(function () { _oPopBody.show(); });

}


function addFiles(_Dafaulvalue) {
    var strRamdon = (parseInt(Math.random() * 99)).toString();
    var myDate = new Date();
    var myMon = myDate.getMonth() + 1;
    var myTime = myDate.getFullYear().toString() + myMon.toString() + myDate.getDate().toString() + myDate.getHours().toString() + myDate.getMinutes().toString() + myDate.getSeconds().toString() + strRamdon;
    var timeFile = "file" + myTime;
    var timeTR = "tr" + myTime;

    var newTR = $('<tr class="pt20" id=\'' + timeTR + '\'></tr>'); //定义一个tr
    var newTD = $('<td></td>')
    $('<input id=\'' + timeFile + '\' name="inputFile" readonly="true" class="mr5 nameIpt" type="text" runat="server" value=\'' + _Dafaulvalue + '\' />').appendTo(newTD);
    $('<img style="margin: 0px 0px 0px 3px; border: 0px currentColor;" align="absmiddle" onclick="return commonInputPicker(\'attach\',\'' + timeFile + '\');" src="/App_Themes/Blue/images/menu_open.gif" alt="">').appendTo(newTD);
    if ($("#tableUpFile tr").length >= 1) {
        $('<img class="ml30 vm" alt="删除"    style=" cursor:pointer;" onclick="RemoveInput(this);" src="/App_Themes/Blue/images/close.gif"/>').appendTo(newTD);
    }
    newTD.appendTo(newTR);
    $("#tableUpFile").append(newTR);
    myTime += 1;
}

function RemoveInput(_this) {
    $(_this).parent().parent().remove();
}


function GetUpFileName(form) {
    var strValues = "";

    for (var i = 0; i < form.elements.length; i++) {
        var e = form.elements[i];

        if (e.type == "text" && e.name == "inputFile") {
            strValues += e.value + ",";

        }
    }
    $("#fileValue").val(strValues);
}

